;›;**************************************›;›; READ SECTOR FROM DISK›;›; ENTRY:ACC=SECTOR NUMBER›; :BUFFER POINTER POINTS TO SECTOR›; :BUFFER WHERE DATA IS TO BE PUT›; EXIT:CARRY SET IF ANY ERROR›;›;**************************************›;›RSECPROC›;›:STATUS=$A0›;›STASECREG;STORE IN SECTOR REG›LDATRACK›STATRKREG;SET UP TRACK REGISTER›RSEC12LDY#$00;SET UP INDEX POINTER›LDA#$E6›STAWT24E;SET TIME OUT›LDARSECCM;READ SECTOR COMMAND›STACMDREG;PUT INTO COMMAND REGISTER›RSEC01BITDRA;TEST STATUS›BVCRSEC10;TIMEOUT›BPLRSEC01;DATA NOT READY YET›LDADTAREG;LOAD DATA REGISTER›EOR#$FF;COMPLEMENT DATA IF NEED BE›STA(BPNT),Y;STORE IN BUFFER›;LDARTDE;CLEAR TIMEOUT COUNTER›INY›CPYLENTH;COMPARE LENTH OF SECTOR›BNERSEC01;NOT DONE KEEP GETTING DATA›LDA#$01;MASK FOR FDC›RSEC02BITSTREG;CHECK FDC STATUS›BNERSEC02›LDASTREG›EOR#$FF›STASTAT+1›EOR#$FF;PUT IT BACK THE WAY IT WAS›AND#%00101000;CHECK CRC AND›;DELETED DATA MARK›BEQ:RS003›LDA#$01;SET BAD STATUS›STA:STATUS›SEC›BCSRSECXT›:RS003LDA#0;OK NO PROBLEM›STA:STATUS;RETURN GOOD STATUS›CLC›RSECXTRTS›RSEC10LDASTREG›AND#$01›BEQRSEC11›LDA#$E6›JSRSTMO;SET TIMEOUT›BNERSEC01›RSEC11LDAWT64D›LDASTREG›AND#$04;CHECK FOR LOST DATA›BNERSEC12›LDA#$01›STA:STATUS;SET YUCKY STATUS›LDASTREG›EOR#$FF›STASTAT+1;SAVE FDC STATUS›SEC›BCSRSECXT;ERROR EXIT›EPROC›;›;›;**************************************›;›; VERIFY SECTOR JUST READ›;›; ENTRY:ACC=SECTOR NUMBER›; :BUFFER POINTER POINTS TO SECTOR›; :BUFFER WHERE DATA IS TO BE PUT›; EXIT:CARRY SET IF ANY ERROR›;›;**************************************››VSECPROC›;›:STATUS=$A0›;›STASECREG;STORE IN SECTOR REG›LDATRACK›STATRKREG;SET UP TRACK REGISTER›LDA#$00›STA:STATUS›STATEMP;CLEAR FLAG›:VSEC1LDY#$00;SET UP INDEX POINTER›LDX#$00›LDA#$F6›JSRSTMO;SET TIME OUT›LDARSECCM;READ SECTOR COMMAND›STACMDREG;PUT INTO COMMAND REGISTER›:VSEC2BITDRA;TEST STATUS›BVC:VSEC6;TIMEOUT›BPL:VSEC2;DATA NOT READY YET›LDADTAREG;LOAD DATA REGISTER›EOR#$FF;COMPLEMENT DATA›CMP(BPNT),Y;COMPARE WITH BUFFER›BEQ:VSEC3;DATA OK›LDA#$FF›STATEMP;SET FLAG›:VSEC3INY›CPYLENTH;COMPARE LENTH OF SECTOR›BNE:VSEC2;NOT DONE KEEP GETTING DATA›LDA#$01;MASK FOR FDC›:VSEC4BITSTREG;CHECK FDC STATUS›BNE:VSEC4›LDASTREG›EOR#$FF›STASTAT+1›EOR#$FF›AND#%00111000;CHECK FOR ERRORS›BNE:VSEC8›LDA#0;SET GOOD STATUS›STA:STATUS›CLC›:VSEC5LDATEMP;LOAD FLAG›BPL:VSECXT;DATA OK›LDA#$01›STA:STATUS;SET BAD STATUS›SEC›BCS:VSECXT;BAD READ›:VSEC6INC:STATUS›CMP#$02;TRY TWO TIMES›BEQ:VSEC8›LDASTREG›AND#$01›BEQ:VSEC7›LDA#$E6›JSRSTMO;SET TIMEOUT›BNE:VSEC2›:VSEC7LDAWT64D›LDASTREG›AND#$04;CHECK FOR LOST DATA›BNE:VSEC1›:VSEC8LDA#$01›STA:STATUS›SEC›:VSECXTRTS›EPROC›;›;›;**************************************›;›; READ TRACK ROUTINE›;›; ENTRY:NONE›; EXIT:CARRY SET IF ERROR›; :$A0 = # OF BAD SECTORS›;**************************************››RDTKPROC›;›:STATUS=$A0›:COUNT=$A5;COUNT OF SECTORS›;›JSRFINT›JSRNTS›LDATINB›CMP#$FF;BUFFER EMPTY?›BEQ:RTK02;YES READ TRACK›;›CMPNTRK;IS NEW TRACK DIFFERENT?›BNE:RTK02›LDA#01;INDICATE MOTOR NOT TURNED ON›STA:STATUS›CLC;CLEAR CARRY FOR OK›BCC:RTKXT›;›:RTK02JSRMCK;CHECK MOTOR THING›JSRSKTK;SEEK TRACK IF NESSESACARY›BCC:RTK12›LDA#$01;MOTOR WAS ON STATUS›STA:STATUS›BCS:RTKXT›;›:RTK12LDX#0›TXA›STA:COUNT;INIT GOOD SECTOR COUNT›;›:RTK05STATRKCH,X;CLEAR SECTOR STATUS›INX›CPXCONFIG+3;ALL SECTOR STATS CLEAR?›BNE:RTK05›:RTK01LDX:COUNT;LOAD INDEX TO SKTAB›LDASKTAB,X;SECTOR NUMBER›JSRCTS;CHECK FOR SECTOR 1,2,3 ON›;TRACK ZERO›JSRSBPNT;SET BUFFER POINTER›LDYDTAREG;DUMMY READ›JSRRSEC;READ IN SECTOR›LDX:COUNT›LDASKTAB,X;SECTOR NUMBER›TAX›DEX›LDASTAT+1;GET FDC STATUS›STATRKCH,X;STORE IN SECTOR CHECK›;›INC:COUNT›LDA:COUNT›CMPCONFIG+3;ALL SECTORS?›BEQ:RTK03;YES, EXIT›LDASKTAB,X;LOAD SECTOR›JSRSBPNT›JMP:RTK01›:RTK03LDANTRK›STATINB;SET TRACK IN BUFFER IND.›CLC›LDA#$0;INDICATE THAT MOTOR WAS›STA:STATUS;TURNED ON›:RTKXTRTS›EPROC›;›;›;**************************************›;›; SET BUFFER POINTER TO MEMORY PAGE FOR›; SECTOR›; ENTRY:ACC=SECTOR NUMBER›; EXIT:BPNT=PAGE POINTER›;›; ALL REGISTERS PRESERVED›;›;**************************************›;›SBPNTPROC›;›:BFOFF=$82;BUFFER OFFSET›;›STA:BFOFF+1›PHA;SAVE SECTOR NUMBER›TXA;SAVE X REGISTER›PHA›;›DEC:BFOFF+1›;›LDA#$20›BITSTAT;CHECK DENSITIES›BMI:SB128;128 BYTE SECTORS›BEQ:SB128;128 BYTE SECTORS›CLC›LDA:BFOFF+1;THESE ARE 256 BYTE BUFFERS›ADC#HIGH BUFF›STABPNT+1›LDA#$00›STABPNT›BEQ:SBXIT›;›:SB128LDX#$00;DO A 7 BIT SHIFT LEFT›STX:BFOFF›LSR:BFOFF+1›ROR:BFOFF›CLC›LDA#LOW BUFF›ADC:BFOFF›STABPNT›LDA#HIGH BUFF›ADC:BFOFF+1›STABPNT+1›;›:SBXITPLA›TAX;RECOVER X REG›PLA;RECOVER ACC›RTS›EPROC›;›;**************************************›; READ SECTOR›;›; ENTRY:NONE›; EXIT:CARRY SET IF ERROR›;›;**************************************›;›RDSCLDANSEC›JSRSBPNT›JSRCTS;SET LENTH ACORDING TO TRACK 0›;AND SECTOR 1,2,3›LDALENTH;LENTH OF SECTOR›JSRSEND›RTS›;›;**************************************›;›; TURN ON DRIVE MOTOR›;›; ENTRY:NONE›; EXIT:NONE›;›; PRESERVES ALL USED REGISTERS›;›;**************************************›;›MOONPROC›PHA›LDADRA;LOAD DATA REGISTER›AND#$F7;SET CONTROLL BIT LOW›STADRA;FOR MOTOR›LDA#$FF›STAMFLAG;SET MOTOR ON FLAG›LDASTAT›ORA#$10›STASTAT›LDASTPPOS›ORA#$01›STADRB;TURN ON STEPPER MOTOR›PLA›RTS›EPROC›;›;**************************************›;›; TURN OFF DRIVE MOTOT›;›; ENTRY:NONE›; EXIT:NONT›;›; PRESERVES ALL REGISTERS›;›;**************************************›;›MOOFFPROC›PHA›LDADRA;LOAD DATA REGISTER›ORA#$08;SET MOTOR CONTROL BIT HIGH›STADRA›LDASTAT›AND#$EF›STASTAT›LDADRB;TURN OFF STEPPER MOTOR›STASTPPOS›ORA#%00111100;ALL BITS OFF›STADRB›PLA›RTS›EPROC›;›;**************************************›;›; INIT 5 SECOND TIMER›;›; ENTRY:NONE›; EXIT:NONE›;›; PRESERVES ALL REGISTERS›;›;**************************************›;›I5SECPHA›LDATL;LOAD TIME LIMIT›STATC›LDA#$97;.1 SECOND INTERVAL›JSRSTMO;START TIMER›PLA›RTS›;›;**************************************›;›; CHECK 5 SECOND TIMER›;›; ENTRY:NONE›; EXIT:CARRY SET IF TIMED OUT›;›; PRESERVES ALL REGISTERS›;›;**************************************›;›CK5SPHA›BITDRA;CHECK FOR TIMER TIMEOUT›BVSCK5SXT›DECTC;DECREMENT TIMER COUNT›LDATC›BEQCK5S01;COUNT ENDED›LDA#97›JSRSTMO;RESET TIMER›CLC›BCCCK5XIT›CK5S01LDARTDE;DISABLE TIMER›SEC›BCSCK5XIT›CK5SXTCLC›CK5XITPLA›RTS›;›;**************************************›;›; WRITE SECTOR›;›; ENTRY:ACC=SECTOR TO WRITE›; :BUFFER POINTER POINTS TO DATA›; EXIT:CARRY SET IF ANY ERRORS›;›;**************************************›;›WSECPROC›;›:STATUS=$A0›;›STASECREG›LDATRACK›STATRKREG;SET UP SECTOR TO WRITE TO›WSEC01LDY#$00›LDA#$E6›STAWT24E›LDAWSECCM;WRITE SECTOR COMMAND›STACMDREG›WSEC02LDA(BPNT),Y›EOR#$FF;LOAD AND COMPLEMENT DATA›WSEC03BITDRA;CHECK FOR WHEN FDC REDY›BVCWSEC10;TIME OUT ERROR›BPLWSEC03;LOOP UNTIL READY›STADTAREG;SEND DATA TO FDC›LDAWT64D›INY›CPYLENTH;COMPARE WITH SECTOR LENTH›BNEWSEC02›LDA#$01›WSEC04BITSTREG›BNEWSEC04;LOOP UNTIL DONE›LDASTREG›LDA#0›STA:STATUS;SET STATUS OK!›CLC›RTS›WSEC10LDASTREG›AND#$01;CHECK FOR BUSY›BEQWSEC20›LDA#$E6›JSRSTMO›BNEWSEC02›WSEC20LDAWT64D›LDASTREG›AND#$04;CHECK FOR LOST DATA›BNEWSEC01›LDASTREG›LDA#$01›STA:STATUS;SET STATUS YUCKY!›SEC›RTS›EPROC›;›;›;**************************************›;›;ITRKS : INITIALIZE A SINGLE DENSITY›;TRACK BY SETTING UP A MODEL TRACK›;IN RAM AT LOCATION $2000›;›;ENTRY : SECT IS SECTOR #›; TRCK IS TRACK #›;EXIT : MODEL TRACK AT $2000›;›;**************************************››ITRKSLDA#$00›STABPNT›LDA#$20›STABPNT+1;COPY BASE POINTER››LDY#0;INITIALIZE INDEX›LDX#$AC;# OF BYTES TO LOOP›LDA#0;INIT BYTES TO $FF›TKHDR1DEX;DECREMENT LOOP COUNT›STA(BPNT),Y;STORE DATA›JSRIBPNT;INC BASE›CPX#0;STOP LOOP?›BNETKHDR1››LDA#$FC;INIT BYTE TO $FC›STA(BPNT),Y;STORE DATA›JSRIBPNT;INC BASE;UPDATE BASE INDEX››LDX#16›LDA#0›TKHDR3DEX›STA(BPNT),Y›JSRIBPNT;INC BASE›CPX#0›BNETKHDR3;END OF TRACK HEADER?››LDX#0›STXSECT;SECT IS SECTOR # INDEX››; BEGIN SECTOR FORMAT MODEL››SHDR1LDX#6;6 BYTES›LDA#0;LOAD 0›SHDR2DEX›STA(BPNT),Y›JSRIBPNT;INC BASE›CPX#0›BNESHDR2››LDA#$FE›STA(BPNT),Y›JSRIBPNT;INC BASE››LDATRCK;TRACK #›STA(BPNT),Y›JSRSTKP;SAVE TRACK POINTER IN SKTAB›JSRIBPNT;INC BASE››LDA#0;SIDE #›STA(BPNT),Y›JSRIBPNT;INC BASE››LDXSECT;SECTOR #›LDASKTAB,X;GET SECTOR FROM SKEW›STA(BPNT),Y›JSRIBPNT;INC BASE››LDA#0;SECTOR LENGTH = 128›STA(BPNT),Y›JSRIBPNT;INC BASE››LDA#$F7;FOR 2 BYTE CRC›STA(BPNT),Y›JSRIBPNT;INC BASE››LDX#17;11 BYTES›LDA#0;LOAD $FF›SHDR3DEX›STA(BPNT),Y›JSRIBPNT;INC BASE›CPX#0›BNESHDR3››LDA#$FB›STA(BPNT),Y›JSRIBPNT;INC BASE››LDX#128›LDA#$FF›SDATADEX›STA(BPNT),Y›JSRIBPNT;INC BASE›CPX#0›BNESDATA››LDA#$F7›STA(BPNT),Y›JSRIBPNT;INC BASE››LDX#12›LDA#0›SECENDDEX›STA(BPNT),Y›JSRIBPNT;INC BASE›CPX#0›BNESECEND››INCSECT›LDASECT;INCREMENT SECTOR INDEX›CMP#18;DONE WITH ALL 18 SECTORS?›BEQITRKXT;YES, NOW PAD TRACK›JMPSHDR1››ITRKXTRTS;DONE WITH TRACK IMAGE!›;›;**************************************›;›; STKP: SAVE POINTER TO TRACK NUMBER›;›; ENTRY:SECT=CURRENT SECTOR INDEX›; EXIT:POINTER IN SKTAB›;›; SAVE X,Y AND A REGISTERS›;›;**************************************›;›STKPPROC›;›PHA;SAVE ACC›TXA;SAVE X REG›PHA›LDASECT;GET SECTOR INDEX›ASLA;MULTIPLY BY 2›TAX;MOVE TO INDEX REGISTER›LDABPNT›STATNPNT,X;STORE IN TRACK NUMBER›INX›LDABPNT+1›STATNPNT,X;POINTER AREA›PLA;GET X REG›TAX›PLA;GET ACC›RTS›;›;**************************************›;›; CTS: CHECK TRACK/SECTOR STATUS›;›; ENTRY:ACC = SECTOR›; :NTRK = TRACK›; EXIT:LENTH APROPRIATLY SET›;›; SAVE ACC,X,Y›;›;**************************************›;›CTSPROC›;›PHA;SAVE ACCUMULATOR›LDACONFIG+7;SET LENTH›STALENTH›LDANTRK;CHECK TRACK NUMBER›BNE:EXIT;NOT ZERO JUST EXIT›PLA;GET SECTOR NUMBER›CMP#4;CHECK FOR LESS THAT 4›BCS:EXIT1›PHA;SAVE SECTOR NUMBER AGAIN›LDA#$80;SET LENTH TO 128›STALENTH›:EXITPLA;GET ACC BACK›:EXIT1RTS›EPROC›;›LINKD2:DD15M5.ASM›TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT